﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DAO;
using DTO;

namespace BUS
{
    public class DichVu_BUS
    {
        private static DichVu_BUS m_instance = null;

        public static DichVu_BUS Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new DichVu_BUS();
                return m_instance;
            }
        }

        /// <summary>
        /// LẤY TOÀN BỘ DỊCH VỤ
        /// </summary>
        /// <returns></returns>
        public List<DichVu_DTO> LayToanBoDichVu()
        {
            List<DichVu_DTO> result = new List<DichVu_DTO>();

            DataTable dt = DichVu_DAO.Instance.LayToanBoDichVu();
            if (dt == null)
                return null;

            DataRowCollection list = dt.Rows;
            if (list.Count == 0)
                return result;
            for (int i = 0; i < list.Count; i++)
            {
                DataRow row = list[i];
                string madv = (string)row["MaDV"];
                string tendv = (string)row["TenDV"];
                decimal dongia2 = (decimal)row["DonGia"];
                long dongia = (long)dongia2;
                DichVu_DTO sp = new DichVu_DTO(madv, tendv, dongia);
                result.Add(sp);
            }
            return result;
        }

        /// <summary>
        /// Lấy toàn bộ danh sách mã sản phẩm
        /// </summary>
        /// <returns></returns>
        public List<string> LayToanBoMaDichVu()
        {
            List<string> result = new List<string>();

            DataTable dt = DichVu_DAO.Instance.LayToanBoMaDichVu();
            if (dt == null)
                return null;

            DataRowCollection list = dt.Rows;
            if (list.Count == 0)
                return result;
            for (int i = 0; i < list.Count; i++)
            {
                DataRow row = list[i];
                string madv = (string)row["MaDV"];
                result.Add(madv);
            }
            return result;
        }

        /// <summary>
        /// THÊM DỊCH VỤ MỚI VÀO CSDL
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public bool ThemDichVu(DichVu_DTO dv)
        {
            return DichVu_DAO.Instance.ThemDichVuMoi(dv.TenDichVu, dv.DonGia);
        }


        /// <summary>
        /// Cập nhật dịch vụ
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public bool CapNhatDichVu(DichVu_DTO dv)
        {
            return DichVu_DAO.Instance.CapNhatDichVu(dv.MaDichVu, dv.TenDichVu, dv.DonGia);
        }


        /// <summary>
        /// Xóa dịch vụ
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public bool XoaDichVu(DichVu_DTO dv)
        {
            return DichVu_DAO.Instance.XoaDichVu(dv.MaDichVu);
        }


        /// <summary>
        /// Lấy thông tin dịch vụ
        /// </summary>
        /// <param name="madv"></param>
        /// <returns></returns>
        public DichVu_DTO LayThongTinDichVu(string madv)
        {
            DataTable dt = DichVu_DAO.Instance.LayThongTinDichVu(madv);
            // Bi loi
            if (dt == null)
                return null;

            DataRowCollection list = dt.Rows;
            if (list.Count == 0)
                return null;

            DataRow row = list[0];
            string mad = (string)row["MaDV"];
            string tendv = (string)row["TenDV"];
            decimal dongia2 = (decimal)row["DonGia"];
            long dongia = (long)dongia2;

            return new DichVu_DTO(mad, tendv, dongia);
        }
    }
}
